from aip import AipFace
import base64
def face_client():
    APP_ID = '************'
    API_KEY = '************'
    SECRET_KEY = '************'
    client =AipFace(APP_ID,API_KEY,SECRET_KEY)
    return client

def baiduAI_face_match(client,img1,img2):
    result = client.match([
        {
            'image': str(base64.b64encode(open(img1, 'rb').read()), 'utf-8'),
            'image_type': 'BASE64',
        },
        {
            'image': str(base64.b64encode(open(img2, 'rb').read()), 'utf-8'),
            'image_type': 'BASE64',
        }
    ])
    #print(result)
    if result['result'] != None:
        if result['result']['score'] >= 75:
            return '相似度>75%,基本判定为同一人'
        else:
            return '相似度<75%,不能判定为同一人'
    else:
        return False

client = face_client()
result = baiduAI_face_match(client,'img1.jpg', 'img2.jpg')
print(result)
